//
//  YMFOrderInfoManager.swift
//  FlyingPigeon
//
//  Created by yang on 2019/5/26.
//  Copyright © 2019年 a. All rights reserved.
//

import Foundation

class YMFOrderInfoManager: NSObject {
    
    var orderInfos = [YMFOrderModel]()
    var path: String = {
        let docPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last!
        let path = (docPath as NSString).appendingPathComponent("orderInfo.data")
        return path
    }()
    
    static let  manager: YMFOrderInfoManager = {
         return YMFOrderInfoManager()
    }()
    
    class func share() -> YMFOrderInfoManager {
        return manager
    }
    
    func getData() -> [YMFOrderModel] {
        
       return NSKeyedUnarchiver.unarchiveObject(withFile: path) as? [YMFOrderModel] ?? [YMFOrderModel]()
        
    }
    
    func saveData(orderInfo: [YMFOrderModel]?) {
        if let info = orderInfo {
            NSKeyedArchiver.archiveRootObject(info, toFile: path)
            
        }
    }
    
    private override init() {
        super.init()
    }
    
   
    
    
}
